CC = g++
SOURCES = $(wildcard *.cpp)  
OBJSFINSH = 
OBJS = $(patsubst %.cpp,%.o, $(SOURCES))  
DEPS = $(patsubst %.cpp,%.d, $(SOURCES))  
CBUILD_PATH = ./build/ 
TARGET = mainzxcqweasdg.d
MAKE_PUBLIC = ./public/
BUILD_PATH = ../build/
PLUGIN_PATH = ./build/plugin/
CFLAGS = -std=c++11	-lpthread -g

export CFLAGS
export BUILD_PATH

define cmd_finsh


if [ ! -d $(CBUILD_PATH) ]; then \
    mkdir -p $(CBUILD_PATH); \
fi

if [ ! -d $(PLUGIN_PATH) ]; then \
    mkdir -p $(PLUGIN_PATH); \
fi
	cp *.o $(CBUILD_PATH)
	cp finsh.mk ./build/makefile
	cp userPass.lua ./build/userPass.lua
endef

all:init $(TARGET)

$(TARGET):$(OBJS)
	$(cmd_finsh)
	@echo 完成!
	$(MAKE) -C $(CBUILD_PATH)
	touch $@
init:
	@echo 准备初始化其他makefile！
	$(MAKE) -C $(MAKE_PUBLIC)

%.d: %.h
	touch $@
	$(CC) -c $(patsubst %.h,%.cpp, $<) $(CFLAGS)
	
%.o:%.cpp
	$(CC) -c $< $(CFLAGS)
#%.d: %.cpp
#	$(CC) -M $< > $@ $(CFLAGS)

#sinclude $(DEPS)  
cleanall:clean
	@echo 清除所有!
	rm -rf ./build/
	$(MAKE) cleanall -C $(MAKE_PUBLIC)

clean:
	@echo 清除生成文件！
	rm -f *.o *.d
run:
	$(MAKE) run -C $(CBUILD_PATH)
debug:
	$(MAKE) debug -C $(CBUILD_PATH)
so:
	$(MAKE) -C ./network/
	$(MAKE) -C ./juzLog/
	$(MAKE) -C ./thread/
cso:
	$(MAKE) cleanall -C ./network/
	$(MAKE) cleanall -C ./juzLog/
	$(MAKE) cleanall -C ./thread/
ne:
	$(MAKE) -C ./network/
log:
	$(MAKE) -C ./juzLog/

